Fast methods of learning distance metric for classification and retrieval

ABSTRACT

A nearest-neighbor-based distance metric learning process includes applying an exponential-based loss function to provide a smooth objective; and determining an objective and a gradient of both hinge-based and exponential-based loss function in a quadratic time of the number of instances using a computer.

The present application claims priority to Provisional Application Ser. No. 61/491,606 filed May 31, 2011, the content of which is incorporated by reference.

BACKGROUND

Nearest neighbor classifier is one of the most popular approaches for classification. It is naturally suitable for tasks involving many classes. For example, there are more than thousands of classes in the case of face recognition and OCR for Chinese characters. The success of nearest neighbor classifier highly depends on the quality of distance metric of data, therefore metric learning has been an important component of machine learning. A learned distance metric can also be transferred to similar tasks. For example, a distance metric can be learned from a group of subjects with many training face images, and use the learned metric to recognize a different group of subjects with only one face image per subject. One major issue of metric learning is its prohibitive computation costs, because the training algorithms typically operate with pairs or triples of training examples.

Many approaches exist for distance metric learning. Unsupervised approaches, such as PCA family, have been widely used. For example, Eigenface has been used for face recognition and gender recognition. In the cases where additional label information is available, supervised approaches may generally lead to higher-quality distance metrics. Among supervised approaches, linear discriminant analysis, such as Fisherface, is widely used because of simplicity and relatively high quality. Machine learning practitioners usually pursue approaches resulting into higher quality metrics, as the cost of computation is decreasing.

To learn metric for nearest neighbor classifiers in many-class problems, we prefer nearest-neighbor-based approaches, because the triple constraints are weaker than pairwise constraints, and directly related to the decision rule of nearest-neighbor classification—in order to correctly classify, essentially we need to ensure the triple-wise relationship that the distance between data and from the same class is smaller than that between and from different classes, while caring less about the absolute values of pair-wise distances. Thereafter in this paper, we will call the triple-wise approach by nearest-neighbor-based metric learning.

SUMMARY

In one aspect, a nearest-neighbor-based distance metric learning process includes applying an exponential-based loss function to provide a smooth objective; and determining an objective and a gradient of both hinge-based and exponential-based loss function in a quadratic time of the number of instances using a computer.

Implementations of the above aspects may include one or more of the following. The method includes adding regularization term to control a generalization error. The method includes adding trace norm constraints to control a generalization error. The method includes using exponential-based loss function to generate a smooth loss objective. A hinge loss function can be used for learning metrics. The method includes using a sorted order to determine the objective and gradient. An exponential-based loss function for learning metrics can be used. A class soft-max distance and between-class soft-min distance can be used to determine the objective and gradient. The soft-max distance and soft-min distance can be:

$\begin{matrix} {{{\delta_{\pm}(x)} = {{\delta_{+}(x)} - {\delta_{-}(x)}}},{\delta_{+}(x)}} \\ {{= {\ln{\sum\limits_{y \sim x}\;{\exp\left( {d^{2}\left( {y,x} \right)} \right)}}}},{\delta_{-}(x)}} \\ {= {{- \ln}{\sum\limits_{{z \smallsetminus} \sim x}\;{{\exp\left( {- {d^{2}\left( {z,x} \right)}} \right)}.}}}} \end{matrix}$ The method includes using concavity of x^(p) (0<p1<1) and log(1+b x) (b>0) to determine an up-bound of a loss function. The learned distance metric can be used to classify, recognize or retrieve data. The regularization terms and constraint terms control generalization error and reduce overall error. The loss function and its gradient can be:

$\begin{matrix} {l = {E_{x,{y \sim x}}{\frac{1}{N_{x^{-}}}\left\lbrack {{\left( {1 + {d^{2}\left( {y,x} \right)}} \right){Z_{x,y}}} - {\sum\limits_{z \in Z_{x,y}}\;{d^{2}\left( {z,x} \right)}}} \right\rbrack}}} \\ {\overset{.}{l} = {E_{x,{y \sim x}}\frac{1}{N_{x^{-}}}{\sum\limits_{z \in Z_{x,y}}\left\{ {{\left( {y - x} \right)\left( {y - x} \right)} - {\left( {z - x} \right)\left( {z - x} \right)}} \right\}}}} \\ {= {{\sum\limits_{x,v}\;{{w_{x,v}\left( {v - x} \right)}\left( {v - x} \right)}} = {{X\left( {S - W - W} \right)}X}}} \end{matrix}$ where Z_(x,y) is the set of data not belonging to the class of x and satisfying 1+d²(y,x)≧d²(z,x), Y_(x,z) is the set of data belonging to the same class of x and satisfying 1+d²(y,x)≧d²(z,x), w_(x,v) is

$\frac{Z_{x,v}}{{NN}_{x +}N_{x -}}$ if v in the same class of x,

$- \frac{Y_{x,v}}{{NN}_{x +}N_{x -}}$ if v is not in the same class as x. X is an p×N matrix whose j-th column is the feature vector of x_(j), W is an N×N matrix whose i,j-th element is w_(x) _(i) _(,x) _(j) (or simply written as w_(ij)), S is an N×N diagonal matrix whose i-th diagonal element is Σ_(j)(w_(ij)+w_(ji)), and NN_(x+) is the size of class of x, N_(x−) is the size of data not in the class of x. The method includes determining an exponential type of surrogate function

ψ(ξ)=ξ^(ρ), where ρε(0,1] where the gradient with respect to the squared distance is

$\begin{matrix} {\frac{\partial\overset{\sim}{l}}{\partial d_{ij}^{2}} = {\frac{\rho}{\exp\left\{ {\left( {1 - \rho} \right){\delta_{\pm}\left( x_{i} \right)}} \right\}}\frac{\exp\left\{ {\rho\left( {d_{ij}^{2} - {\delta_{-}\left( x_{i} \right)}} \right)} \right\}}{{NN}_{x_{i} +}}}} \\ {{= w_{ij}},{\forall{j:{x_{j}\text{∼}x_{i}}}}} \end{matrix}$ $\begin{matrix} {\frac{\partial\overset{\sim}{l}}{\partial d_{ik}^{2}} = {\frac{\rho}{\exp\left\{ {\left( {1 - \rho} \right){\delta_{\pm}\left( x_{i} \right)}} \right\}}\frac{{- \exp}\left\{ {\rho\left( {{\delta_{+}\left( x_{i} \right)} - d_{ik}^{2}} \right)} \right\}}{{NN}_{x_{i} -}}}} \\ {{= w_{ik}},{\forall{k:{{x_{k} \smallsetminus \text{∼}}x_{i}}}}} \end{matrix}$ The method includes determining a logit type surrogate function as:

${{\psi(\xi)} = \frac{\ln\left( {1 + {\beta\xi}} \right)}{\ln\left( {1 + \beta} \right)}},$ where β>0 where the gradient with respect to the squared distance is

$\begin{matrix} {\frac{\partial\overset{\sim}{l}}{\partial d_{ij}^{2}} = {\frac{\beta}{\left( {1 + {\beta\;{\exp\left( {\delta_{\pm}\left( x_{i} \right)} \right)}{\ln\left( {1 + \beta} \right)}}} \right.}\frac{\exp\left( {d_{ij}^{2} - {\delta_{-}\left( x_{i} \right)}} \right)}{{NN}_{x_{i} +}}}} \\ {{= w_{ij}},{\forall{j:{x_{j}\text{∼}x_{i}}}}} \end{matrix}$ $\begin{matrix} {\frac{\partial\overset{\sim}{l}}{\partial d_{ik}^{2}} = \frac{\beta}{\left( {1 + {\beta\;{\exp\left( {\delta_{\pm}\left( x_{i} \right)} \right)}}} \right){\ln\left( {1 + \beta} \right)}}} \\ {{= w_{ik}},{\forall{k:{{x_{k} \smallsetminus \text{∼}}x_{i}}}}} \end{matrix}\frac{- {\exp\left( {{\delta_{+}\left( x_{i} \right)} - d_{ik}^{2}} \right)}}{{NN}_{x_{i} -}}$ The method includes determining a gradient matrix as

$\overset{.}{\overset{\sim}{l}} = {{\sum\limits_{x_{i},x_{j}}\;{{w_{ij}\left( {x_{i} - x_{j}} \right)}\left( {x_{i} - x_{j}} \right)^{T}}} = {{X\left( {S - W - W} \right)}X}}$ where W is an N×N matrix whose i,j-th element is w_(ij), S is an N×N diagonal matrix whose i-th diagonal element is Σ_(j)w_(ij)+w_(ji).

Advantages of the preferred system may include one or more of the following. The system efficiently determines distance metric, which is a crucial component for nearest neighbor classification and information retrieval. The system uses lower-complexity techniques for determining loss functions and their gradients. The system also applies smooth surrogate loss functions to achieve better convergence rates. Evaluation with a number of datasets shows the benefit of efficient computation of gradients and fast convergence rates of smooth loss functions. Overall, the system is advantageous in that it has:

1. Less complexity in the processing.

2. Faster operation in learning the distance metric.

3. Higher quality in the learned metric.

BRIEF DESCRIPTION OF THE DRAWINGS

FIG. 1 shows an exemplary method to process learning metrics.

FIG. 2 shows an exemplary method to determine objective and gradient for a hinge loss case.

FIG. 3 shows an exemplary method to determine objective and gradient for an exponential-based loss case.

DETAILED DESCRIPTION

FIG. 1 shows an exemplary method to generate learning metrics. The process receives input data (101). With the input, the process determines objective and gradient data (102). The metric is updated using gradient (103). In 104, the process checks for convergence. If not, the process loops back to 102 to continue determining objective and gradient data. If convergence is reached, the process exits and returns the desired metric (105). The operation 102 in FIG. 1 is detailed in FIGS. 2-3.

FIG. 2 shows an efficient method to compute objective and gradient for hinge loss case. The process of FIG. 2 efficiently computes gradients for nearest-neighbor-based approaches using hinge loss function. The process reduces the computation to the similar magnitude as those pairwise-based approaches. The invention uses sorted order by distance as done in Step (202) and (203). This reduces computation complexity from O(N³ p) to O(N²p). In FIG. 2, the process determines distances between the data points (201). The process then sorts instances by distance (202). The objective and gradient is updated by a sorted order (203). The process then returns the objective and gradient to the process of FIG. 1 (204).

FIG. 3 shows an exemplary method to determine objective and gradient for an exponential-based loss case. The process first determines distances between data points (301). The process then determines the soft-max for within class distances and the soft-min for between class distances (302). The process then updates the objective and gradient using the soft-max and soft-min distances (303). The process then returns

Other embodiments computes gradient for smooth surrogate functions. The smoothness of those loss functions makes it possible to use Nesterov's method to achieve a faster convergence rate.

Next, details of the distance determination are discussed. One embodiment uses asquared distance metric, defined as d²(x,y; A)=(x−y)^(T) A(x−y) for all pairs of instances x and y, where A is positive semi-definite p×p matrix. The nearest-neighbor error is ε=Pr(d ²(y,x;A)≧d ²(z,x;A)|y˜x,z\˜x),  (1) where y˜x denotes that x and y belongs to the same class, z\˜x denotes that z belong to another class. Usually, we make an assumption that y is uniformly sampled from the class that x belongs to and z is uniformly sampled from any class that x does not belong to. The goal of this metric learning problem is to learn the parameter A from a set of N training instancesto minimize the error ε in Eq. (1). φ be a nondecreasing surrogate function,and φ(0)=1. By Markov inequality,nearest neighbor error is bounded by l(A)+R _(N)  (2) where l(A)=E_(x,y˜x,z\˜x)φ(d²(y,x; A)−d²(z,x; A)) is the true expectation over all instances, and R_(N) is the generalization error.

The concept of target neighbors is introduced to choose y from a subset of instances in the same class which are close to instance x. With this concept, we modify the notation y˜x as y is a target neighbor of x, where y is assumed to be uniformly sampled from the target neighbors of x. Our tests show that choosing more target neighbors (or all same-class instances) is preferred when the dimension is high and/or the number of exemplar instances is small.

To minimize the prediction error, the regularized framework in Eq. (3) minimizes l(A) and control R_(N), according to the analysis of the generalization error in Section 3.

$\begin{matrix} {{{\min\limits_{A}\;{f(A)}} = {{\frac{\lambda}{2}{A}_{F}^{2}} + {l(A)}}}{{{{subject}\mspace{14mu}{to}\mspace{14mu} A} \succ 0},{{{tr}(A)} \leq C},}} & (3) \end{matrix}$ where ∥A∥_(F) is the Frobenius norm of A, which ensures the generalization error, and the trace tr(A) further controls the generalization error and enforce that A is of low rank. Let A be the matrix that optimizes f. For simplicity, d²(x,y; A) becomes d²(x,y).

To solve the constrained problem of Eq. (3), we can use projected gradient descent method. In each step, the process performs a projection after a gradient step.

An efficient process for Hinge Loss is discussed next. When we use hinge loss function φ(ξ)=[1+ξ]₊, Problem (3) differs from the large margin nearest neighbor classifier (LMNN) by normalization, regularization and trace constraint. LMNN does not normalize the loss for each instances. In practice, when the number of targeted neighbors for each class is the same, the overall empirical loss of LMNN and that in Eq. (2) are not much different as long as no class dominates in the dataset. In more general cases, Eq. (2) proves that the normalized loss can bound the expected error. In addition, LMNN uses the total within-class squared distance as regularization, while we use Frobenius norm as regularization based on the generalization analysis. The trace constraint is used to enforce the low rank, and has certain effect on the generalization error based on our analysis.

In one embodiment, the loss function and its gradient can be written as

$\begin{matrix} {l = {E_{x,{y \sim x}}{\frac{1}{N_{x^{-}}}\left\lbrack {{\left( {1 + {d^{2}\left( {y,x} \right)}} \right){Z_{x,y}}} - {\sum\limits_{z \in Z_{x,y}}\;{d^{2}\left( {z,x} \right)}}} \right\rbrack}}} \\ {\overset{.}{l} = {E_{x,{y \sim x}}\frac{1}{N_{x^{-}}}{\sum\limits_{z \in Z_{x,y}}\left\{ {{\left( {y - x} \right)\left( {y - x} \right)} - {\left( {z - x} \right)\left( {z - x} \right)}} \right\}}}} \\ {= {{\sum\limits_{x,v}\;{{w_{x,v}\left( {v - x} \right)}\left( {v - x} \right)}} = {{X\left( {S - W - W} \right)}X}}} \end{matrix}$ where Z_(x,y) is the set of data not belonging to the class of x and satisfying 1+d²(y,x)≧d²(z,x), Y_(x,z) is the set of data belonging to the same class of x and satisfying 1+d²(y,x)≧d²(z,x), w_(x,v) is

$\frac{Z_{x,v}}{{NN}_{x +}N_{x -}}$ if v in the same class of x,

$- \frac{Y_{x,v}}{{NN}_{x +}N_{x -}}$ if v is not in the same class as x. X is an p×N matrix whose j-th column is the feature vector of x_(j), W is an N×N matrix whose i,j-th element is w_(x) _(i) _(,x) _(j) (or simply written as w_(ij)), S is an N×N diagonal matrix whose i-th diagonal element is Σ_(j)(w_(ij)+w_(ji)), and NN_(x+) is the size of class of x, N_(x−) is the size of data not in the class of x.

The efficient computation of the loss function and its gradient efficiently depends on whether we can compute all |Y_(x,z)|, |Z_(x,y)| and Σ_(zεZ) _(x,y) d²(z,x) within O(N) time for any give instance x. It does not require to compare d²(y,x) with d²(z,x) for all y and all z for any given x, if we sort them by squared distances, and compute those terms incrementally. The total computation is within O(N²p+N² log N+Np²) time

Pseudo code for one exemplary process to determine objective and gradient of LMNN is as follows:

1: $\left. f\leftarrow{\frac{\lambda}{2}{A}_{F}^{2}\mspace{14mu}{and}\mspace{14mu} T}\leftarrow{\lambda A} \right.,{{s\mspace{14mu}{be}\mspace{14mu} a\mspace{14mu}{zero}\mspace{14mu}{vector}\mspace{14mu}{of}\mspace{14mu}{size}\mspace{14mu} N}\;;}$ 2: for i:x_(i) ε D do 3:  compute distance d_(il) ² = d² (x_(i), x_(l)) for all l; 4:  sort queues P = {l:x_(l)~x_(i)} and Q = {l:x_(l)

x_(i)} by d_(il) ²; 5:  Z = N|P||Q|; t ← 0; n ← 0; j ← pop(P); k ← pop(Q); v be a zero vector of size N; 6:  while j ≠ 0 do 7:   if k ≠ 0 and d_(ik) ² ≦ d_(ij) ² + 1 then 8:    t ← t + d_(ik) ²; n ← n + 1; v_(k) ← −(1 + |P|)/Z; k ← pop(Q); 9:   else 10:    f ← f + (nd_(ij) ² + n − t)/Z; v_(j) ← n/Z; j ← pop(P); 11:   end if 12:  end while 13: s ← s + v; s_(i) ← s_(i) + sum(v); T ← T − (Xv)^(T)x_(i) − x_(i) ^(T) (Xv); 14: end for 15: return f and {dot over (f)} = T + X^(T) diag(s)X.

To achieve the optimal convergence rate, we need smooth surrogate functions. However, certain embodiments can not be modified to work for general surrogate functions. To achieve efficient computation for loss functions and their gradients, we introduce a special family of exponential-based smooth surrogate function. Let φ(ξ)=ψ(exp(ξ), where ψ be a concave nondecreasing function and ψ(0₊)=0, ψ(1)=1. Because of the concavity of ψ, we have

$\begin{matrix} \begin{matrix} {{l(A)} = {{E_{x,{y \sim x},{{z \smallsetminus} \sim x}}{\psi\left( {\exp\left( {{d^{2}\left( {y,x} \right)} - {d^{2}\left( {z,x} \right)}} \right)} \right)}} \leq}} \\ {E_{x}{\phi\left( {\delta_{\pm}(x)} \right)}} \\ {{= {\overset{\sim}{l}(A)}},} \end{matrix} & (4) \\ {where} & \; \\ \begin{matrix} {{{\delta_{\pm}(x)} = {{\delta_{+}(x)} - {\delta_{-}(x)}}},{\delta_{+}(x)}} \\ {{= {\ln{\sum\limits_{y \sim x}\;{\exp\left( {d^{2}\left( {y,x} \right)} \right)}}}},{\delta_{-}(x)}} \\ {= {{- \ln}{\sum\limits_{{z \smallsetminus} \sim x}\;{{\exp\left( {- {d^{2}\left( {z,x} \right)}} \right)}.}}}} \end{matrix} & \; \end{matrix}$ Clearly, δ₊(x) is the soft-max of the square distances of all instances similar to x, and δ⁻(x) is the soft-min of the square distances of all instances not similar to x. The concavity of ψ allows us to reduce the comparison among the triples to the comparison between soft-max of within-distance and soft-min of between-distance, which enables us to efficiently compute the empirical loss function and its gradient within O(N²p+Np²) time. The details are shown in the following examples of ψ:

1. ψ(ξ)=ξ^(ρ), where ρε(0,1]. This is the exponential type of surrogate function. The gradient with respect to the squared distance is

$\begin{matrix} {\frac{\partial\overset{\sim}{l}}{\partial d_{ij}^{2}} = {\frac{\rho}{\exp\left\{ {\left( {1 - \rho} \right){\delta_{\pm}\left( x_{i} \right)}} \right\}}\frac{\exp\left\{ {\rho\left( {d_{ij}^{2} - {\delta_{-}\left( x_{i} \right)}} \right)} \right\}}{{NN}_{x_{i} +}}}} \\ {{= w_{ij}},{\forall{j:{x_{j}\text{∼}x_{i}}}}} \end{matrix}$ $\begin{matrix} {\frac{\partial\overset{\sim}{l}}{\partial d_{ik}^{2}} = {\frac{\rho}{\exp\left\{ {\left( {1 - \rho} \right){\delta_{\pm}\left( x_{i} \right)}} \right\}}\frac{{- \exp}\left\{ {\rho\left( {{\delta_{+}\left( x_{i} \right)} - d_{ik}^{2}} \right)} \right\}}{{NN}_{x_{i} -}}}} \\ {{= w_{ik}},{\forall{k:{{x_{k} \smallsetminus \text{∼}}x_{i}}}}} \end{matrix}$

2.

${{\psi(\xi)} = \frac{\ln\left( {1 + {\beta\xi}} \right)}{\ln\left( {1 + \beta} \right)}},$ where β>0. This is the logit type of surrogate function. The gradient with respect to the squared distance is

$\begin{matrix} {\frac{\partial\overset{\sim}{l}}{\partial d_{ij}^{2}} = {\frac{\beta}{\left( {1 + {\beta\;{\exp\left( {\delta_{\pm}\left( x_{i} \right)} \right)}{\ln\left( {1 + \beta} \right)}}} \right.}\frac{\exp\left( {d_{ij}^{2} - {\delta_{-}\left( x_{i} \right)}} \right)}{{NN}_{x_{i} +}}}} \\ {{= w_{ij}},{\forall{j:{x_{j}\text{∼}x_{i}}}}} \end{matrix}$ $\begin{matrix} {\frac{\partial\overset{\sim}{l}}{\partial d_{ik}^{2}} = \frac{\beta}{\left( {1 + {\beta\;{\exp\left( {\delta_{\pm}\left( x_{i} \right)} \right)}}} \right){\ln\left( {1 + \beta} \right)}}} \\ {{= w_{ik}},{\forall{k:{{x_{k} \smallsetminus \text{∼}}x_{i}}}}} \end{matrix}\frac{- {\exp\left( {{\delta_{+}\left( x_{i} \right)} - d_{ik}^{2}} \right)}}{{NN}_{x_{i} -}}$ For all these cases, {tilde over (l)}(A) is convex with respect to A. The gradient matrix is

$\begin{matrix} {\overset{.}{\overset{\sim}{l}} = {{\sum\limits_{{({x_{i},x_{j}})} \in x}\;{{w_{ij}\left( {x_{i} - x_{j}} \right)}\left( {x_{i} - x_{j}} \right)^{T}}} = {{X\left( {S - W - W} \right)}X}}} & (5) \end{matrix}$ W is an N×N matrix whose i,j-th element is w_(ij), S is an N×N diagonal matrix whose i-th diagonal element is Σ_(j)w_(ij)+w_(ji).

For each instance, we can compute all distances within O(Np) time, each δ₊(x) and δ⁻(x) within O(N) time, all w_(ij) within O(N), and additional matrix gradient computation with O(p²). Thus the total time for {tilde over (l)} and {dot over ({tilde over (l)} is O(N²p+Np²). Given the above equations, the algorithm of computing the losses and its deritives should be straightforward, thus we do not list the pseudo code here. The memory consumption can be limited with O(N+p²).

In tests, we find the performance is usually sensitive to the choice of the number of target neighbors. For classification cases, if we have a large number of exemplar instances, a small number of target neighbors usually results into a better performance, because the exemplar instances far from the testing instance in the Euclidean metric are usually far from the testing instance in the learned metric when the dimension is low. Thus the uniform distribution assumption of selecting exemplar instances does not hold. The choice of smaller number of target neighbors can benefit the performance. However, in retrieval cases, the exemplar instance is just the query instance, therefore it is better to use most of the instances as the target neighbors, even if they are not that similar to the query instance.

The system is based on an analysis of the generalization error of nearest-neighbor-based distance metric learning approaches. The analysis suggests to use the regularized minimization framework for distance metric learning to control the generalization error. The system uses efficient techniques to compute objective loss functions and their gradients for hinge, exponential and logit loss with O(N²p+Np²+p³) time and O(N+p²) working memory. Embodiments of the system use the smooth surrogate functions for faster convergence rates than that nonsmooth hinge loss function. Tests confirm the accuracy of these approaches and the efficiency of the computation.

The invention may be implemented in hardware, firmware or software, or a combination of the three. Preferably the invention is implemented in a computer program executed on a programmable computer having a processor, a data storage system, volatile and non-volatile memory and/or storage elements, at least one input device and at least one output device.

By way of example, a block diagram of a computer to support the system is discussed next. The computer preferably includes a processor, random access memory (RAM), a program memory (preferably a writable read-only memory (ROM) such as a flash ROM) and an input/output (I/O) controller coupled by a CPU bus. The computer may optionally include a hard drive controller which is coupled to a hard disk and CPU bus. Hard disk may be used for storing application programs, such as the present invention, and data. Alternatively, application programs may be stored in RAM or ROM. I/O controller is coupled by means of an I/O bus to an I/O interface. I/O interface receives and transmits data in analog or digital form over communication links such as a serial link, local area network, wireless link, and parallel link. Optionally, a display, a keyboard and a pointing device (mouse) may also be connected to I/O bus. Alternatively, separate connections (separate buses) may be used for I/O interface, display, keyboard and pointing device. Programmable processing system may be preprogrammed or it may be programmed (and reprogrammed) by downloading a program from another source (e.g., a floppy disk, CD-ROM, or another computer).

Each computer program is tangibly stored in a machine-readable storage media or device (e.g., program memory or magnetic disk) readable by a general or special purpose programmable computer, for configuring and controlling operation of a computer when the storage media or device is read by the computer to perform the procedures described herein. The inventive system may also be considered to be embodied in a computer-readable storage medium, configured with a computer program, where the storage medium so configured causes a computer to operate in a specific and predefined manner to perform the functions described herein.

The invention has been described herein in considerable detail in order to comply with the patent Statutes and to provide those skilled in the art with the information needed to apply the novel principles and to construct and use such specialized components as are required. However, it is to be understood that the invention can be carried out by specifically different equipment and devices, and that various modifications, both as to the equipment details and operating procedures, can be accomplished without departing from the scope of the invention itself.

Although specific embodiments of the present invention have been illustrated in the accompanying drawings and described in the foregoing detailed description, it will be understood that the invention is not limited to the particular embodiments described herein, but is capable of numerous rearrangements, modifications, and substitutions without departing from the scope of the invention. The following claims are intended to encompass all such modifications. 

What is claimed is:
 1. A nearest-neighbor-based distance metric learning process implemented by a computer, comprising: applying an exponential-based loss function to provide a smooth objective; and determining an objective and a gradient of both hinge-based and exponential-based loss function in a quadratic time of the number of instances using a computer; wherein the loss function and its gradient comprises: $\begin{matrix} {l = {E_{x,{y \sim x}}{\frac{1}{N_{x^{-}}}\left\lbrack {{\left( {1 + {d^{2}\left( {y,x} \right)}} \right){Z_{x,y}}} - {\sum\limits_{z \in Z_{x,y}}\;{d^{2}\left( {z,x} \right)}}} \right\rbrack}}} \\ {\overset{.}{l} = {E_{x,{y \sim x}}\frac{1}{N_{x^{-}}}{\sum\limits_{z \in Z_{x,y}}\left\{ {{\left( {y - x} \right)\left( {y - x} \right)} - {\left( {z - x} \right)\left( {z - x} \right)}} \right\}}}} \\ {= {{\sum\limits_{x,v}\;{{w_{x,v}\left( {v - x} \right)}\left( {v - x} \right)}} = {{X\left( {S - W - W} \right)}X}}} \end{matrix}$ where d is distance, x and y are data points, z is sampled from a class which x does not belong to, Z_(x,y) is the set of data not belonging to the class of x and satifying 1+d²(y,x)≧d²(z,x), w_(x,v) is $\frac{Z_{x,v}}{{NN}_{x +}N_{x -}}$ if v in the same class of x, w_(x,v) is $- \frac{Y_{x,v}}{{NN}_{x +}N_{x -}}$ if v is not in the same class as x, X is an p×N matrix whose j-th column is the feature vector of x_(j), W is an N×N matrix whose i,j-th element is w_(x) _(i) _(,x) _(j) , S is an N×N diagonal matrix whose i-th diagonal element is Σ_(j)(w_(ij)+w_(ji)), NN_(x+) is the size of class of x, N_(x−) is the size of data not in the class of x, and E is the expection over values x,y^(˜x).
 2. The method of claim 1, using an ordered list of instances sorted by distance to determine the objective and gradient of a hinge-based loss function.
 3. The method of claim 1, comprising using a sorted order to determine the objective and gradient.
 4. The method of claim 1, comprising applying an exponential-based loss function for learning metrics.
 5. The method of claim 4, comprising using a class soft-max distance and between-class soft-min distance to determine the objective and gradient.
 6. The method of claim 1, comprising using the learned distance metric to classify, recognize or retrieve data.
 7. The method of claim 1, wherein regularization terms and constraint terms control generalization error and reduce overall error.
 8. The method of claim 1, comprising determining an exponential type of surrogate function ψ(ξ)=ξ^(ρ), where ρε(0,1] where the gradient with respect to the squared distance is $\begin{matrix} {\frac{\partial\overset{\sim}{l}}{\partial d_{ij}^{2}} = {\frac{\rho}{\exp\left\{ {\left( {1 - \rho} \right){\delta_{\pm}\left( x_{i} \right)}} \right\}}\frac{\exp\left\{ {\rho\left( {d_{ij}^{2} - {\delta_{-}\left( x_{i} \right)}} \right)} \right\}}{{NN}_{x_{i} +}}}} \\ {{= w_{ij}},{\forall{j:{x_{j}\text{∼}x_{i}}}}} \end{matrix}$ $\begin{matrix} {\frac{\partial\overset{\sim}{l}}{\partial d_{ik}^{2}} = {\frac{\rho}{\exp\left\{ {\left( {1 - \rho} \right){\delta_{\pm}\left( x_{i} \right)}} \right\}}\frac{{- \exp}\left\{ {\rho\left( {{\delta_{+}\left( x_{i} \right)} - d_{ik}^{2}} \right)} \right\}}{{NN}_{x_{i} -}}}} \\ {{= w_{ik}},{\forall{k:{{x_{k} \smallsetminus \text{∼}}x_{i}}}}} \end{matrix}$ where δ₊(x) is the soft-max of the square distances of all instances similar to x, and δ⁻(x) is the soft-min of the square distances of all instances not similar to x, ψ is a concave function, and i,j are matrix elements.
 9. The method of claim 1, comprising determining a gradient matrix as $\overset{.}{\overset{\sim}{l}} = {{\sum\limits_{x_{i},x_{j}}\;{{w_{ij}\left( {x_{i} - x_{j}} \right)}\left( {x_{i} - x_{j}} \right)^{T}}} = {{X\left( {S - W - W} \right)}X}}$ where X is a p×N matrix whose j-th column is the feature vector of x_(j), W is an N×N matrix whose i,j-th element is w_(ij), S is an N×N diagonal matrix whose i-th diagonal element is Σ_(j)w_(ij)+w_(ji).
 10. A system to perform nearest-neighbor-based distance metric learning implemented with a computer, comprising: means for applying an exponential-based loss function to provide a smooth objective; and means for determining an objective and a gradient of both hinge-based and exponential-based loss function in a quadratic time of the number of instances using a computer; wherein the loss function and its gradient comprises: $\begin{matrix} {l = {E_{x,{y \sim x}}{\frac{1}{N_{x^{-}}}\left\lbrack {{\left( {1 + {d^{2}\left( {y,x} \right)}} \right){Z_{x,y}}} - {\sum\limits_{z \in Z_{x,y}}\;{d^{2}\left( {z,x} \right)}}} \right\rbrack}}} \\ {\overset{.}{l} = {E_{x,{y \sim x}}\frac{1}{N_{x^{-}}}{\sum\limits_{z \in Z_{x,y}}\left\{ {{\left( {y - x} \right)\left( {y - x} \right)} - {\left( {z - x} \right)\left( {z - x} \right)}} \right\}}}} \\ {= {{\sum\limits_{x,v}\;{{w_{x,v}\left( {v - x} \right)}\left( {v - x} \right)}} = {{X\left( {S - W - W} \right)}X}}} \end{matrix}$ where d is distance, x and y are data points, z is sampled from a class which x does not belong to, Z_(x,y) is the set of data not belonging to the class of x and satifying 1+d²(y,x)≧d²(z,x), w_(x,v) is $\frac{Z_{x,v}}{{NN}_{x +}N_{x -}}$ if v in the same class of x, w_(x,v) is $- \frac{Y_{x,v}}{{NN}_{x +}N_{x -}}$ if v is not in the same class as x, X is an p×N matrix whose j-th column is the feature vector of x_(j), W is an N×N matrix whose i,j-th element is w_(x) _(i) _(x) _(j) , S is an N×N diagonal matrix whose i-th diagonal element is Σ_(j)(w_(ij)+w_(ji)), NN_(x+) is the size of class of x, N_(x−) is the size of data not in the class of x, and E is the expection over values x, y^(˜x).
 11. The system of claim 10, comprising: means for adding regularization term to ensure the generalization error; and means for adding trace norm constraints to ensure the generalization error.
 12. The system of claim 10, comprising means for learning metric with an exponential-based loss function and means for using class soft-max distance and between-class soft-min distance to determine the objective and gradient.
 13. The system of claim 10, comprising means for using the learned distance metric to classify, recognize or retrieve data. 